using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPrimeryAttactState : PlayerState
{
    private int comboCounter;

    private float lastTimeAttacked;
    private float comboWindow = 2;
    public PlayerPrimeryAttactState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        if(comboCounter > 2|| Time.time> lastTimeAttacked+comboWindow) {
            comboCounter = 0;
        }
        stateTimer = .2f;
        player.anim.SetInteger("ComboCounter",comboCounter);
        float attackDir = player.facingDir;
        if (xInput != 0)
        {
            attackDir = xInput;
        }

        player.SetVelocity(player.attackMovement[comboCounter]*attackDir,rb.velocity.y);
    }

    public override void Exit()
    {
        base.Exit();
        player.StartCoroutine("BusyFor", .1f);
        comboCounter++;
        lastTimeAttacked = Time.time;
    }

    public override void Update()
    {
        base.Update();
        if(stateTimer <0)
        rb.velocity = new Vector2(0, 0);
        if (triggleCalled)
        {
            stateMachine.ChangeState(player.idleState);

        }
    }
}
